home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / programm / GNU_C++ / LIB / CFLIB-11.LZH / src / objc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-12  |  6.7 KB  |  347 lines

  1. #include <stdlib.h>
  2. #ifdef __MINT__
  3. #include <macros.h>
  4. #include <support.h>
  5. #define itoa(a,b,c)    _itoa(a,b,c)
  6. #define ltoa(a,b,c)    _ltoa(a,b,c)
  7. #define ultoa(a,b,c)    _ultoa(a,b,c)
  8. #endif
  9.  
  10. #include "intern.h"
  11.  
  12.  
  13. /*****************************************************************************/
  14. int get_obtype(OBJECT *tree, int obj, short *ud)
  15. {
  16.     int    type;
  17.  
  18.     if (ud != NULL)
  19.         *ud = FALSE;
  20.     type = tree[obj].ob_type & 0x00FF;
  21.  
  22.     /* Special: im Falle UserDef steht im oberen Byte der Original-Typ! */
  23.     if (type == G_USERDEF)
  24.     {
  25.         type = (tree[obj].ob_type & 0xFF00) >> 8;
  26.         if (ud != NULL)
  27.             *ud = TRUE;
  28.     }
  29.     return type;
  30. }
  31.  
  32. /*****************************************************************************/
  33. void set_obspec(OBJECT *tree, int obj, long spec)
  34. {
  35.     short    ud;
  36.  
  37.     get_obtype(tree, obj, &ud);
  38.     if (ud)
  39.         tree[obj].ob_spec.userblk->ub_parm = spec;
  40.     else
  41.         tree[obj].ob_spec.index = spec;
  42. }
  43.  
  44. long get_obspec(OBJECT *tree, int obj)
  45. {
  46.     short    ud;
  47.  
  48.     get_obtype(tree, obj, &ud);
  49.     if (ud)
  50.         return tree[obj].ob_spec.userblk->ub_parm;
  51.     else
  52.         return tree[obj].ob_spec.index;
  53. }
  54.  
  55. /*****************************************************************************/
  56. void set_string(OBJECT *tree, int obj, char *text)
  57. {
  58.     long    spec;
  59.     int    type;
  60.  
  61.     spec = get_obspec(tree, obj);
  62.     type = get_obtype(tree, obj, NULL);
  63.     switch (type)
  64.     {
  65.         case G_BUTTON  :
  66.         case G_STRING  :
  67.         case G_TITLE   :
  68.         case G_SHORTCUT:
  69.             strcpy((char *)spec, text);
  70.             break;
  71.  
  72.         case G_CICON   :
  73.         case G_ICON    :
  74.             strcpy (((ICONBLK*)spec)->ib_ptext, text);
  75.             break;
  76.  
  77.         case G_TEXT    :
  78.         case G_BOXTEXT :
  79.         case G_FTEXT   :
  80.         case G_FBOXTEXT:
  81.             strcpy(((TEDINFO*)spec)->te_ptext, text);
  82.             break;
  83.  
  84.         default:
  85.         {
  86.             char    s[30];
  87.             sprintf(s, "[3][CF-Lib Panic: set_string()!|Objekt %d hat unbekannten Typ %d|!][Abbruch]", obj, type);
  88.             form_alert(1, s);
  89.         }
  90.             break;
  91.     }
  92. }
  93.  
  94. void get_string(OBJECT *tree, int obj, char *text)
  95. {
  96.     long    spec;
  97.     int    type;
  98.  
  99.     spec = get_obspec(tree, obj);
  100.     type = get_obtype(tree, obj, NULL);
  101.     switch (type)
  102.     {
  103.         case G_BUTTON  :
  104.         case G_STRING  :
  105.         case G_TITLE   :
  106.         case G_SHORTCUT:
  107.             strcpy(text, (char*)spec);
  108.             break;
  109.  
  110.         case G_CICON   :
  111.         case G_ICON    :
  112.             strcpy(text, ((ICONBLK*)spec)->ib_ptext);
  113.             break;
  114.  
  115.         case G_TEXT    :
  116.         case G_BOXTEXT :
  117.         case G_FTEXT   :
  118.         case G_FBOXTEXT:
  119.             strcpy(text, ((TEDINFO*)spec)->te_ptext);
  120.             break;
  121.         
  122.         default:
  123.         {
  124.             char    s[30];
  125.             sprintf(s, "[3][CF-Lib Panic: get_string()!|Objekt %d hat unbekannten Typ %d|!][Abbruch]", obj, type);
  126.             form_alert(1, s);
  127.         }
  128.             text[0] = EOS;
  129.             break;
  130.     }
  131. }
  132.  
  133. void set_int(OBJECT *tree, int obj, int i)
  134. {
  135.     char    tmp[20];
  136.     
  137.     itoa(i, tmp, 10);
  138.     set_string(tree, obj, tmp);
  139. }
  140.  
  141. int get_int(OBJECT *tree, int obj)
  142. {
  143.     char    tmp[20];
  144.     
  145.     get_string(tree, obj, tmp);
  146.     return atoi(tmp);
  147. }
  148.  
  149. void set_long(OBJECT *tree, int obj, long l)
  150. {
  151.     char    tmp[20];
  152.     
  153.     ltoa(l, tmp, 10);
  154.     set_string(tree, obj, tmp);
  155. }
  156.  
  157. void set_ulong(OBJECT *tree, int obj, unsigned long l)
  158. {
  159.     char    tmp[20];
  160.     
  161.     ultoa(l, tmp, 10);
  162.     set_string(tree, obj, tmp);
  163. }
  164.  
  165. long get_long(OBJECT *tree, int obj)
  166. {
  167.     char    tmp[20];
  168.     
  169.     get_string(tree, obj, tmp);
  170.     return atol(tmp);
  171. }
  172.  
  173. /*****************************************************************************/
  174.  
  175. void set_state(OBJECT *tree, int obj, int state, int set)
  176. {
  177.     if (set)
  178.         tree[obj].ob_state |= state;            /* Status setzen */
  179.     else
  180.           tree[obj].ob_state &= ~ state;        /* Status löschen */
  181. }
  182.  
  183. int get_state(OBJECT *tree, int obj, int state)
  184. {
  185.     return (tree[obj].ob_state & state);
  186. }
  187.  
  188. void tree_state(OBJECT *tree, int start_obj, int state, int set)
  189. {
  190.     int    i;
  191.  
  192.     for (i = tree[start_obj].ob_head; i <= tree[start_obj].ob_tail; i++)
  193.     {
  194.         set_state(tree, i, state, set);
  195.     }
  196. }
  197.  
  198. /*****************************************************************************/
  199. void set_flag(OBJECT *tree, int obj, int flag, int set)
  200. {
  201.     if (set)
  202.         tree[obj].ob_flags |= flag;        /* Flag setzen */
  203.     else
  204.           tree[obj].ob_flags &= ~flag;        /* Flag löschen */
  205. }
  206.  
  207. int get_flag(OBJECT *tree, int obj, int flag)
  208. {
  209.     return (tree[obj].ob_flags & flag);
  210. }
  211.  
  212. int find_flag(OBJECT *tree, int flag)
  213. {
  214.     int obj = -1;
  215.  
  216.     do
  217.     {
  218.         obj++;
  219.         if (tree[obj].ob_flags & flag)
  220.             return obj;
  221.     }
  222.     while (!(tree[obj].ob_flags & LASTOB));
  223.     return -1;
  224. }
  225.  
  226. /*****************************************************************************/
  227. void get_objframe(OBJECT *tree, int obj, GRECT *r)
  228. {
  229.     int    d, i;
  230.     int    type,
  231.             shadow = 0,
  232.             outline = 0,
  233.             line = 0;
  234.  
  235.     objc_offset(tree, obj, &r->g_x, &r->g_y);
  236.     r->g_w = tree[obj].ob_width;
  237.     r->g_h = tree[obj].ob_height;
  238.  
  239.     type = get_obtype(tree, obj, NULL);
  240.     switch (type)
  241.     {
  242.         case G_STRING :
  243.         case G_SHORTCUT :
  244.         case G_ICON :
  245.         case G_CICON :
  246.             /* nichts mehr zu tun */
  247.             return;
  248.  
  249.         case G_BUTTON:
  250.             line = 1;
  251.             if (tree[obj].ob_flags & DEFAULT)
  252.                 line++;
  253.             if (tree[obj].ob_flags & EXIT)
  254.                 line++;
  255.             if (line && tree[obj].ob_state & SHADOWED)
  256.                 shadow = 2 * line;
  257.             break;
  258.  
  259.         case G_TEXT:
  260.         case G_FTEXT:
  261.             line = -(tree[obj].ob_spec.tedinfo->te_thickness);
  262.             if (line && (tree[obj].ob_state & SHADOWED))
  263.                 shadow = abs(line * 2);
  264.             else
  265.                 line = 0;
  266.             break;
  267.  
  268.         case G_BOXTEXT :
  269.         case G_FBOXTEXT:
  270.             line = -(tree[obj].ob_spec.tedinfo->te_thickness);
  271.             if (line && (tree[obj].ob_state & SHADOWED))
  272.                 shadow = abs (line * 2);
  273.             break;
  274.  
  275.         case G_BOX:
  276.         case G_IBOX:
  277.         case G_BOXCHAR:
  278.             line = -(tree[obj].ob_spec.obspec.framesize);
  279.             if (line && tree[obj].ob_state & SHADOWED)
  280.                 shadow = abs (line * 2);
  281.             break;
  282.  
  283.         default:
  284. /*
  285.         {
  286.             char    s[80];
  287.             sprintf(s, "[3][CF-Lib Hinweis: get_objframe()!|Objekt %d hat unbekannten Typ %d|!][soso]", obj, type);
  288.             form_alert(1, s);
  289.         }
  290. */
  291.             return ;
  292.     }
  293.  
  294.     if (tree[obj].ob_state & OUTLINED)
  295.         outline = 3;
  296.  
  297.     if (line > 0)
  298.     {
  299.         outline = max(outline, line);
  300.         shadow += line;
  301.     }
  302.  
  303.     if (outline)
  304.     {
  305.         r->g_x -= outline;
  306.         r->g_y -= outline;
  307.         r->g_w += outline;
  308.         r->g_h += outline;
  309.     }
  310.  
  311.     if (shadow)
  312.     {
  313.         r->g_w += max(outline, shadow);
  314.         r->g_h += max(outline, shadow);
  315.     }
  316.     else
  317.     {
  318.         r->g_w += outline;
  319.         r->g_h += outline;
  320.     }
  321.  
  322.     if ((appl_xgetinfo(13, &d, &i, &d, &d) && i == 1) &&
  323.          (tree[obj].ob_flags & FL3DACT))
  324.     {
  325.         int    hinc = 0, vinc = 0;
  326.  
  327.         objc_sysvar(0, 6, 0, 0, &hinc, &vinc);
  328.         r->g_x -= hinc;
  329.         r->g_y -= vinc;
  330.         r->g_w += 2 * hinc;
  331.         r->g_h += 2 * vinc;
  332.     }
  333. }
  334.  
  335. /*****************************************************************************/
  336. void redraw_obj(OBJECT *tree, int obj)
  337. {
  338.     GRECT    r;
  339.     
  340.     get_objframe(tree, obj, &r);
  341. #ifdef __MTAES__
  342.     objc_draw(tree, ROOT, MAX_DEPTH, &r);
  343. #else
  344.     objc_draw(tree, ROOT, MAX_DEPTH, r.g_x, r.g_y, r.g_w, r.g_h);
  345. #endif
  346. }
  347.